#!/bin/sh

replacefile(){
    if [ -e "$1" ]; then
        cp "${1}" "${1}.old"
    fi
    install -Dm 0644 "/tmp/$(basename $1)" $1
}

replacefile "/usr/palm/frameworks/mojo2/submissions/99/resources/zh/datetime_table.json"
replacefile "/usr/palm/frameworks/mojo2/submissions/99/resources/zh/cn/datetime_table.json"
replacefile "/usr/palm/frameworks/mojo2/submissions/99/resources/zh/cn/strings.json"
replacefile "/usr/lib/luna/customization/locale.txt"


##
##  workaround:
##
echo "Start workaround..."
rmdir "/media/cryptofs/apps/usr/palm/applications/com.palm.app.findapps/resources/zh_cn/views/add-comment/0000755/"
rmdir "/usr/palm/frameworks/contacts.ui/submission/39/resources/zh/cn/templates/person-filter-list-widget/0000755/"
rm -f /usr/palm/frameworks/contacts.ui/submission/39/resources/zh/cn/templates/person-filter-list-widget/0000755
rm -f /media/cryptofs/apps/usr/palm/applications/com.palm.app.findapps/resources/zh_cn/views/add-comment/0000755


for i in `cat /tmp/filelist.txt`; do
    if [[ ! -f "$i" ]] && [[ -f "${i}0000644" ]]; then
        echo "replace ${i}0000644"
        mv "${i}0000644" "$i"
    fi
done


echo "Workaround finished."
echo

cd /tmp
rm  -f datetime_table.json locale.txt filelist.txt
cd $OLDPWD

echo "Install zh-cn language pack successfully!"
echo

exit 0